package com.epoint.mobileoa.ui.mail;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.adapter.MailDraftAdp;
import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.db.DBHelp;
import com.epoint.mobileoa.model.Draft;

/**
 * @author liyc
 * @time 2012-2-8 下午4:39:24
 * @annotation 
 */
public class DraftListView extends SuperView {

	private ListView lv;
	private List<Draft> draftlist;
	private List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
	
	@Override
	public void initControls() {
		lv = (ListView) findViewById(R.id.lv_mailstyle);
		lv.setOnItemClickListener(this);
		draftlist = DBHelp.getDraftList(this,fp.getUserguid());
		for(int i=0;i<draftlist.size();i++){
			Map<String, Object> map = new HashMap<String, Object>();
			if(draftlist.get(i).hasattach.equals("1")){
				map.put("attachimg", R.drawable.mailattach2);
				map.put("hasattach","1");
			}
			else{
				map.put("attachimg", 0);
				map.put("hasattach","0");
			}
			map.put("mailimg", R.drawable.view_folder_unread);
			map.put("mailtitle", draftlist.get(i).mailtitle);
			map.put("mailguid", draftlist.get(i).draftguid);
			map.put("mailsavetime", draftlist.get(i).draftsavetime);
			list.add(map);
		}
		MailDraftAdp mda = new MailDraftAdp(this, list);
		lv.setAdapter(mda);
	}

	@Override
	public void refresh(Object... param) {
	}

	@Override
	public int getLayoutInt() {
		return R.layout.layout_mailstyle;
	}
	
	@Override
	public String setTitle() {
		return "草稿箱";
	}
	
	@Override
	public void onItemClick(AdapterView<?> parent, View view,
			int position, long id) {
		
		Intent it = new Intent(this, MailSendView.class);
		it.putExtra("viewtitle", "草稿详情");
		it.putExtra("mailtitle", draftlist.get(position).mailtitle);
		it.putExtra("sjrnames", draftlist.get(position).receivername);
		it.putExtra("sjrguids", draftlist.get(position).receiveguid);
		it.putExtra("csrnames", draftlist.get(position).chaosongrename);
		it.putExtra("csrguids", draftlist.get(position).chaosongrenguid);
		it.putExtra("mailcontent", draftlist.get(position).mailcontent);
		it.putExtra("draftguid", draftlist.get(position).draftguid);
		it.putExtra("attachname", draftlist.get(position).attachname);
		it.putExtra("attachpath", draftlist.get(position).attachpath);
		it.putExtra("draftguid", draftlist.get(position).draftguid);
		it.putExtra("pagetype", 1);
		startActivity(it);
		finish();
	}

	@Override
	public void refreshForNewTask(int TaskId,Object... param) {
	}

}
